import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/model/update_file_model.dart';

import '../model/customer_info_model.dart';
import '../net/response/upload_file_response_data.dart';

class UploadElderCaseViewModel extends BaseViewModel {
  List<String>? images;
  dynamic elderId;

  UploadElderCaseViewModel(BuildContext context,
      {this.images, @required this.elderId})
      : super(context) {
    if (images == null) {
      images = [];
    }
  }

  var model = CustomerInfoModel();
  var uploadModel = UploadFileModel();

  Future<void> uploadCase() async {
    showLoadingDialog(msg: '上传中....');
    try {
      var uploadList = <UploadFileResponseData>[];
      for (var file in images!) {
        var result = await uploadModel.uploadFile(file);
        uploadList.add(result);
      }
      var attchId = uploadList.map((e) => e.id).join(",");
      var data =
          await model.uploadElderCase(elderId: elderId, attachIds: attchId);
      hideDialog();
      showToast("上传成功");
      finish(data: true);
    } catch (e) {
      showToast(NetErrorUtils.getNetError(e));
      hideDialog();
    }
  }
}
